package com.sfilyh.servelt.admin;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sfilyh.util.DBUtil;
import com.sfilyh.util.StringUtils;


@WebServlet("/bz-admin/delArticle")
public class delArticle extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	String id = request.getParameter("id");
    	String errorMsg = "删除失败！";
    	if(StringUtils.validate(id)){
    		String sql = "delete from tb_article where id = ? ";
    		DBUtil.update(sql, Integer.parseInt(id));
    		errorMsg = "删除成功！";
    	}    	
    	String referer = request.getHeader("referer");
    	
    	request.setAttribute("msg", errorMsg);
	    request.setAttribute("toUrl", referer);
	    request.getRequestDispatcher("/WEB-INF/views/toUrl.jsp").forward(request, response);
	}    
}
